<?php
/**
 * 标签名称，比如这个使用!{wysiwyg }这样调用
 * 所见即所得编辑器
 * @var string
 */
$self_tag_name = 'wysiwyg';

/**
 * 获取资源路径，比如!{res file='css/site.css'}将返回：http://cache.duoec.com/sites/main/test.duoec.com/template/css/site.css
 * @param array $params 参数
 * @param Smarty $smarty
 */
function smarty_function_wysiwyg($params, &$smarty){
	if(!isset($params['name'])){
		$type = 'kindEditor';//默认使用nicEdit编辑器
	}else{
		$type = trim($params['name']);
	}
	//判断是否存在
	if(!is_dir(ROOT_PATH . '/template/js/editor/' . $type)){
		$type = 'kindEditor';
	}
	$edit_fun = 'load_wysiwyg_' . $type;
	return $edit_fun($params, &$smarty);
}

/**
 * 加载nicEdit编辑器代码
 */
function load_wysiwyg_nicEdit($params, &$smarty){
	
	$html = '<script src="' .CACHE_URL . '/template/js/editor/nicEdit/nicEdit.js" type="text/javascript"></script>';
	$html .= '<script type="text/javascript">bkLib.onDomLoaded(nicEditors.allTextAreas);</script>';
	return $html;
}

function load_wysiwyg_kindEditor($params, &$smarty){
	$html = 
		'<link rel="stylesheet" href="' .CACHE_URL . '/template/js/editor/kindEditor/themes/default/default.css" />
		<link rel="stylesheet" href="' .CACHE_URL . '/template/js/editor/kindEditor/plugins/code/prettify.css" />
		<script src="' .CACHE_URL . '/template/js/editor/kindEditor/kindeditor-min.js" type="text/javascript"></script>
		<script charset="utf-8" src="' .CACHE_URL . '/template/js/editor/kindEditor/lang/' . LANGUAGE . '.js"></script>
		<script charset="utf-8" src="' .CACHE_URL . '/template/js/editor/kindEditor/plugins/code/prettify.js"></script>
		<script>
			KindEditor.ready(function(K) {
				$("textarea.wysiwyg").each(function(){
					init_kindEditor_editor(this);
				});
			});
		</script>';
	return $html;
}